package com.wmwj.hxlj.controller;

import com.wmwj.hxlj.entity.Category;
import com.wmwj.hxlj.entity.vo.CategoryResult;
import com.wmwj.hxlj.service.CategoryService;
import com.wmwj.hxlj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategotyController {
    @Autowired
    private CategoryService categoryService;

    //返回分类列表
    @GetMapping("/getCategoryList")
    public Result<CategoryResult> getCategoryList(){
        return categoryService.getCategoryList();
    }

    //添加分类
    @RequestMapping("/addCategory")
    public Result<String> addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }

    //通过id删除分类
    @DeleteMapping("/deleteCategory")
    public Result<String> deleteCategory(@RequestParam Integer id){
//        System.out.println(id);
        return categoryService.deleteCategory(id);
    }

    //修改分类
    @PutMapping("/updateCategory")
    public Result<String> updateCategory(@RequestBody Category category) {
        return categoryService.updateCategory(category);
    }

}
